//---------------------------------------------------------
//	hash table definition
//---------------------------------------------------------
#ifndef HASHTABLE_H
#define HASHTABLE_H
#pragma pack(push,1)

#include "hashlist.h"

//---------------------------------------------------------
//	hash table definition
//---------------------------------------------------------
class HashTable
{
public:
	HashTable() : m_nBuckets(0), m_pBuckets(0)	{ /*empty*/	}
	~HashTable();

	// set the number of buckets...
	// must have a Clear(true,true) command between each call
	void	SetNBuckets( u32 nBuckets );

	// clear the table
	void	Clear( bool freeListMemory=false, bool freeBuckets=false );

	// functions by hash
	bool	AddByHash( HASH hashValue, void *pData );
	bool	RemoveByHash( HASH hashValue );

	// functions by type
	template <class X>
	inline	bool	Add( X *pData )
	{
		return AddByHash(pData->MakeHash(),pData);
	}

	template <class X>
	inline	bool	Remove( const X *pData )
	{
		return RemoveByHash(pData->MakeHash());
	}

protected:
	u32			m_nBuckets;
	CHashList	*m_pBuckets;
};

#pragma pack(pop)
#endif
